
pkgname=iproute2
pkgver=4.17.0
pkgrel=1
pkgdesc="IP Routing Utilities"
arch=('x86_64')
license=('GPL2')
url="https://wiki.linuxfoundation.org/networking/start"
depends=('linux-atm' 'perl')
makedepends=('iptables')
options=('!makeflags')
backup=('etc/iproute2/ematch_map' 'etc/iproute2/rt_dsfield' 'etc/iproute2/rt_protos' \
        'etc/iproute2/rt_realms' 'etc/iproute2/rt_scopes' 'etc/iproute2/rt_tables')
source=("https://www.kernel.org/pub/linux/utils/net/iproute2/${pkgname}-${pkgver}.tar.xz"
        'iproute2-fhs.patch')
sha256sums=('6fa991b092315887775b9e47dc6a89af7ae09dd3ad4ccff754d055c566b4be6e'
            'fcfeb0428d88bcab3ff272ec739031f00e7e94365e114364f8d546814577f3c5')

prepare() {
  cd ${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/iproute2-fhs.patch

  sed -i 's|-Werror||' Makefile
}

build() {
  cd ${pkgname}-${pkgver}

  ./configure
   make
}
   
package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR=$pkgdir install
  
  # allow loopback to be started before /usr is mounted
  mkdir -p ${pkgdir}/sbin
  mv ${pkgdir}/usr/sbin/ip ${pkgdir}/sbin/ip
  ln -s /sbin/ip ${pkgdir}/usr/sbin/ip

  # add libnetlink
  install -Dm644 include/libnetlink.h ${pkgdir}/usr/include/libnetlink.h
  install -Dm644 lib/libnetlink.a ${pkgdir}/usr/lib/libnetlink.a
}
